<template>
    <base-breadcrumb class="allPlan">
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card :bordered="false">
            <b-table
                :scroll="{x:1376}"
                ref="table"
                :columns="columns"
                :request="loadData"
                :exportConfig="{use:true,select:'其他类合同入库选中',all:'其他类合同入库全部'}"
            >
                <template slot="prefix" slot-scope="ref">
                    <a-button v-btn-permission="'lcm_006_add_01'" type="primary" icon="plus"
                              @click="$router.push({path: '/legal/branch-contract/other-type/add'})">
                        新增
                    </a-button>
                </template>
                <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
                <template slot="reviewAuditStatus" slot-scope="text, record, index">
                    <list-status :status="record.reviewAuditStatus" :text="text"></list-status>
                </template>
                <template slot="sealAuditStatus" slot-scope="text, record, index">
                    <list-status :status="record.sealAuditStatus" :text="text"></list-status>
                </template>
                <template slot="operation" slot-scope="text, record, index">
                    <MoreButton>
                        <a
                            @click="$router.push({path: '/legal/branch-contract/other-type/detail',query:{id:record.id}})"
                        >查看</a>
                        <a v-if="record.reviewAuditStatus === 'DRAFT' || record.reviewAuditStatus === 'REJECTED'"
                              @click="handleEdit(record, 1)">编辑</a>
                        <!--                                                <span @click="handleEdit(record, 1)">编辑</span>-->

                                <a v-btn-permission="'lcm_006_sea_05'" @click="handleEdit(record, 2)">用印 </a>
                                <template
                                    v-if="record.reviewAuditStatus === 'DRAFT' || record.sealAuditStatus === 'DRAFT'">
                                    <a @click="handleDel(record.id)">删除</a>
                                </template>
                        <!--                        <a  @click="handleDel(record.id)">删除</a>-->

                        <a @click="chooseRow = record;$refs.approval.open()">审批意见</a>
                    </MoreButton>
                </template>
            </b-table>
        </a-card>
        <approval ref="approval" title="审批意见" :row="chooseRow"></approval>
    </base-breadcrumb>
</template>

<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany'
import SelectProject from '@/components/Select/SelectProject'
import otherTypeApi from '@/api/legal/branchContract/otherType'
import approval from './components/approval'

export default {
    name: 'otherTypeIndex',
    components: { approval },
    data() {
        return {
            columns: [
                {
                    title: '合同名称',
                    dataIndex: 'contractName',
                    width: 160
                },
                {
                    title: '所属分公司',
                    dataIndex: 'branchCompany',
                    width: 150
                },
                {
                    title: '项目名称',
                    dataIndex: 'project',
                    width: 150
                },

                {
                    title: '合同对方 ',
                    dataIndex: 'otherParty',
                    width: 120

                },
                {
                    title: '合同价（万元）',
                    dataIndex: 'amount',
                    width: 120
                },
                {
                    title: '主办人',
                    dataIndex: 'creatorName',
                    width: 120
                },
                {
                    title: '评审状态',
                    dataIndex: 'reviewAuditStatusStr',
                    scopedSlots: { customRender: 'reviewAuditStatus' },
                    width: this.STATUS_WIDTH
                },
                {
                    title: '用印状态',
                    dataIndex: 'sealAuditStatusStr',
                    scopedSlots: { customRender: 'sealAuditStatus' },
                    width: this.STATUS_WIDTH
                },
                {
                    title: '操作',
                    width: 240,
                    fixed: 'right',
                    scopedSlots: { customRender: 'operation' }
                }
            ],
            searchArr: [
                // 搜索框
                {
                    name: '合同名称',
                    type: 'input',
                    value: 'contractName'
                },
                {
                    name: '所属分公司',
                    valueKey: 'branchCompanyId',
                    type: SelectSubCompany
                },
                // {
                //     name: '项目名称',
                //     type: SelectProject,
                //     valueKey: 'projectId'
                // },

                {
                    name: '合同对方',
                    type: 'input',
                    value: 'otherParty'
                },
                {
                    name: '合同价',
                    type: 'rangeInput',
                    value: 'amount'
                },
                {
                    name: '主办人',
                    type: 'input',
                    value: 'creatorIds'
                },
                {
                    name: '评审状态',
                    type: 'select',
                    value: 'reviewAuditStatus',
                    data: this.STATUS
                },
                {
                    name: '状态',
                    type: 'select',
                    value: 'sealAuditStatus',
                    data: this.STATUS
                }
            ],
            loadData: (params) => {
                return otherTypeApi.findListByMain({}, Object.assign(params, this.queryParam))
            },
            queryParam: {},
            chooseRow: null
        }
    },
    methods: {
        search(val) {
            this.queryParam = val || {}
            this.$refs.table.getData(null, true)
        },
        handleDel(id) {
            let params = id ? [id] : this.selectId
            this.$delList2(otherTypeApi.deleteBymain, () => {
                this.search()
            }, { ids: params })

        },
        handleEdit(record = {}, step) {
            this.$router.push({
                path: '/legal/branch-contract/other-type/add',
                query: {
                    id: record && record.id || '',
                    step
                }
            })
        }
    }
}
</script>
